package com.tianzj.mvc.system.shiro;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.springframework.beans.factory.annotation.Autowired;

import com.tianzj.mvc.system.pojo.SysUser;
import com.tianzj.mvc.system.service.SysUserService;
import com.tianzj.util.MD5Utils;

public class CustomCredentialsMatcher  extends SimpleCredentialsMatcher {

	@Autowired
	private SysUserService sysUserService;
	
	@Override 
	public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {  
		UsernamePasswordToken token = (UsernamePasswordToken) authcToken; 
	    SysUser userNew = new SysUser();
	    userNew.setUserName(token.getUsername());
	    userNew.setPassword(MD5Utils.MD5(String.valueOf(token.getPassword())));
	    SysUser sysUser = sysUserService.getByUserNameAndPass(userNew);
	    if(sysUser!=null){
	    	return true;
	    }else{
	    	return false;
	    }
	}
}
